from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Dict, Any

class NLURequest(BaseModel):
    text: str

app = FastAPI(title="Natural Language Understanding (NLU) Service")

@app.post("/nlu", response_model=Dict[str, Any])
async def understand_text(request: NLURequest):
    """
    接收文本并返回其结构化的意图和槽位。
    该端点将调用文心（Ernie）客户端。
    """
    # 占位逻辑
    # 在实际实现中，你会使用预定义的提示
    # 并在这里调用wenxin_client。
    # result = await wenxin_client.get_intent(request.text)

    # 目前，根据输入返回一个模拟响应
    if "播放" in request.text:
        song_name = request.text.replace("播放", "").strip()
        return {
            "intent": "play_music",
            "slots": {"song_name": song_name}
        }
    
    return {
        "intent": "unknown",
        "slots": {}
    }


@app.get("/")
def read_root():
    return {"message": "NLU Service is running"} 